<?php
class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
{
    protected function _initApplication()
    {
        //__log_debug(__FILE__, __LINE__, __METHOD__, '---------->>>');

        $application_ini_file = '';
        $application_ini_file .= __get_configs_dir();
        $application_ini_file .= DIRECTORY_SEPARATOR;
        $application_ini_file .= 'application.ini';
        $config = new Zend_Config_Ini($application_ini_file, APPLICATION_ENV);
        Zend_Registry::set('config', $config);

        ini_set('session.gc_probability', 1);
        ini_set('session.gc_divisor', 1000);
        
        //session.iniファイルの統合
        $sessionConfig = $config->sessionini;
        Zend_Session::setOptions($sessionConfig->toArray());
        Zend_Session::start();
        //---------------------------------------- 
        // 以下の命令を追加することで、CMSと連携してセッションが使用できる
        setcookie(session_name(), session_id(), 0);
        //---------------------------------------- 
        $apm_session = new Zend_Session_Namespace('apm');
        Zend_Registry::set('apm_session', $apm_session);
        __log_debug_array(__FILE__, __LINE__, __METHOD__, $_COOKIE);
        
        require_once 'Zend/Loader/Autoloader.php';
        $autoloader = Zend_Loader_Autoloader::getInstance();
        $autoloader->setFallbackAutoloader(true);
        //__log_debug(__FILE__, __LINE__, __METHOD__, '----------<<<');
    }
    protected function _initView()
    {
        //__log_debug(__FILE__, __LINE__, __METHOD__, '---------->>>');

        $view = __get_apm_view_object();
        $viewRenderer = Zend_Controller_Action_HelperBroker::getStaticHelper('ViewRenderer');
        $viewRenderer->setView($view)
                     ->setViewBasePathSpec($view->getEngine()->template_dir)
                     ->setViewScriptPathSpec(':module/views/scripts/:controller.:suffix')
                     ->setViewScriptPathNoControllerSpec(':action.:suffix')
                     ->setViewSuffix('tpl');

        //__log_debug(__FILE__, __LINE__, __METHOD__, '----------<<<');
    }
    protected function _initLogging()
    {
        //__log_debug(__FILE__, __LINE__, __METHOD__, '---------->>>');

        require_once 'Zend/Log.php';    
        require_once 'Zend/Log/Writer/Stream.php';

        $app_log_file = '';
        $app_log_file .= dirname(APPLICATION_PATH);
        $app_log_file .= DIRECTORY_SEPARATOR;
        $app_log_file .= 'temp';
        $app_log_file .= DIRECTORY_SEPARATOR;
        $app_log_file .= 'logs';
        $app_log_file .= DIRECTORY_SEPARATOR;
        $app_log_file .= 'app.log';

        $logger = new Zend_Log();
        $writer = new Zend_Log_Writer_Stream($app_log_file);
        $logger->addWriter($writer);
        Zend_Registry::set('log', $logger);

        //__log_debug(__FILE__, __LINE__, __METHOD__, '----------<<<');
    }
}
?>
